/*
 * @Author: byron
 * @Date: 2021-09-28 16:25:18
 * @LastEditTime: 2021-10-06 11:06:51
 */
import router from '@/router'
export function getPageOffset(page, limit) {
    return (page - 1) * limit
}

export function genImgURL(url, w, h) {
    if (!h) {
        h = w
    }
    url += `?param=${w}y${h}`
    return url
}

export function goMv(id) {
    router.push(`/mv/${id}`)
}

export function createSong(song) {
    const {
        id,
        name,
        img,
        artists,
        duration,
        albumId,
        albumName,
        mvId,
        ...rest
    } = song

    const newSong = {
        id,
        name,
        img,
        artists,
        duration,
        albumName,
        url: genSongPlayUrl(song.id),
        artistsText: genArtistisText(artists),
        durationSecond: duration / 1000,
        // 专辑 如果需要额外请求封面的话必须加上
        albumId,
        // mv的id 如果有的话 会在songTable组件中加上mv链接。
        mvId,
        ...rest,
    }
    return newSong
}
function genSongPlayUrl(id) {
    return `https://music.163.com/song/media/outer/url?id=${id}.mp3`
}
export function genArtistisText(artists) {
    return (artists || []).map(({ name }) => name).join('/')
}

export function getKebabCase(str) {
    return str.replace(/[A-Z]/g, function(item) {
        return '-' + item.toLowerCase()
    })
}
